const { defineConfig } = require('@vue/cli-service')
const Components = require('unplugin-vue-components/webpack')
const AutoImport = require('unplugin-auto-import/webpack')
const { VantResolver } = require('@vant/auto-import-resolver')

const { resolve, relative } = require('path')
module.exports = defineConfig({
  // transpileDependencies: true,
  publicPath:'./',
  devServer: {
    client: {
      overlay: false,
    },
   
    https: false,
    proxy: {
      ['/api']: {
        target: `http://192.168.1.42/`, // 底层代理
        changeOrigin: true,
        pathRewrite: {
          ['^/api']: '',
        },
      },
    },
  },
  configureWebpack() {
    return {
      resolve: {
        alias: {
          '~': resolve(__dirname, '.'),
          '@': resolve(__dirname, 'src'),
          'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
        },
      },
      // plugins: createVuePlugin(),
      performance: {
        hints: false,
      },
      plugins: [
        AutoImport({
          imports: ['vue', 'pinia', 'vue-i18n', 'vue-router'],
          resolvers: [],
          Buffer: ['buffer', 'Buffer'],
          dts: 'unplugin/auto-imports.d.ts',
        }),
        Components({
          resolvers: [VantResolver()],
        }),
      ],
    }
  },
  css: {
    // requireModuleExtension: true,
    sourceMap: true,
    loaderOptions: {
      sass: {
        sassOptions: { outputStyle: 'expanded' },
        additionalData(content, { rootContext, resourcePath }) {
          const relativePath = relative(rootContext, resourcePath)
          if (relativePath.replace(/\\/g, '/') !== 'src/styles/variables.scss')
            return (
              '@use "sass:math";@import "~@/styles/variables.scss";' + content
            )
          return content
        },
      },
    },
  },
})
